using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using UnityEngine;

[Serializable]
public class StringToItemDictDictionary : SerializedDictionary<string, SerializedDictionary<int, Item>> { }

[Serializable]
public class StringToIntDictDictionary : SerializedDictionary<string, int> { }
public class 物品管理器 : 物品管理单例<物品管理器>
{
    

    public StringToItemDictDictionary ItemDictionary = new StringToItemDictDictionary();
    //public Dictionary<string, Dictionary<int,Item>> ItemDictionary = new Dictionary<string, Dictionary<int, Item>>();
    
    public StringToIntDictDictionary ItemCntDictionary = new StringToIntDictDictionary();

    void Start()
    {
        
        Debug.Log("物品管理单例为："+SingleItemManage.name);
    }
    // Update is called once per frame
    void Update()
    {
        
    }

    public void RegisterItem(Item newItem)
    {
        Debug.Log(newItem.ItemId);
        if (!ItemDictionary.ContainsKey(newItem.ItemId))
        {
            Debug.Log(newItem.ItemName + "为新物体");
            ItemDictionary.Add(newItem.ItemId, new SerializedDictionary<int, Item>());
            ItemCntDictionary.Add(newItem.ItemId, 1);
        }
        newItem.Itemcnt = ItemCntDictionary[newItem.ItemId];
        ItemDictionary[newItem.ItemId].Add(newItem.Itemcnt, newItem);
        ItemCntDictionary[newItem.ItemId] += 1;
    }

    private void PrintDictionaryContents()
    {
        foreach (var outerKvp in ItemDictionary)
        {
            Debug.Log($"物品ID: {outerKvp.Key}, 实例数量: {ItemCntDictionary[outerKvp.Key]}");
            foreach (var innerKvp in outerKvp.Value)
            {
                Debug.Log($"  实例编号: {innerKvp.Key}, 物品: {innerKvp.Value.ItemName}");
            }
        }
    }
}
